<template>
	<view>
		<!-- 关联企业的信息 -->
		<view class="">
			<view>
				<uni-section :title="'您正在申请的是： '+name " type="line" />
			</view>
			<u--form labelAlign="left" :data="lablesList">
				<view class="informationCss">
					<u-form-item label="企业名称: " labelWidth="100%" />
					<u-form-item :label="lablesList.name" labelWidth="100%" />
				</view>
				<view class="informationCss">
					<u-form-item label="联系人: " labelWidth="100%" />
					<u-form-item :label="lablesList.contact" labelWidth="100%" />
				</view>

				<view class="informationCss">
					<u-form-item label="联系电话: " labelWidth="100%" />
					<u-form-item :label="lablesList.phone" labelWidth="100%" />
				</view>

				<view class="informationCss">
					<u-form-item label="成立时间: " labelWidth="100%" />
					<u-form-item labelWidth="100%">
						<uni-dateformat :date="lablesList.dateOfEstablishment "
							:format="'yyyy'+'年'+'MM'+'月'+'dd'+'日'" />
					</u-form-item>
				</view>
			</u--form>
			<u--form labelAlign="left">
				<view class="informationCss" style="margin-top: 20rpx;">
					<u-form-item label="申请理由:" labelWidth="100%" />
					<u--textarea placeholder="请描述理由..." v-model="desc" autoHeight />
				</view>
				<view class="infoButton">
					<u-button type="primary" text="提交申请" @click="submitDesc"></u-button>
				</view>
			</u--form>
		</view>

	</view>
</template>

<script>
	export default {

		data() {
			return {
				mode: 'single',
				desc: '',
				name: '',
				lablesList: {},
				userInfo:{}
			}
		},
		onShow() {
			this.getUserInfo()
		},
		onLoad(options) {
			this.id = options.id
			this.name = options.name
			console.log(options);
			this.getList()
		},
		methods: {
			getUserInfo() {
				const that = this
				that.$api.request('user', 'info').then(res => {
					console.log(res.data,12369);
					this.userInfo = res.data
				})
			},
			getList() {
				const that = this
				uni.showLoading({
					title: "正在加载",
				});
				that.$api.request('enterprise', 'detail', {}).then(res => {
					uni.hideLoading();
					that.lablesList = res.data
					console.log(that.lablesList, 11111);
				})
			},
			submitDesc() {
				if (this.desc) {
					// userInfo
					if (this.userInfo.associationId !== -1) {
						uni.showToast({
							title: '已入会，无法申请',
							icon: 'none',
							duration: 1000 
						});
						setTimeout(() => {
							uni.navigateBack()
						}, 800)
					} else {
						this.$api.request('examineAndApprove', 'create', {
							associationId: this.id,
							enterpriseId:this.userInfo.enterpriseId,
							type: 1
						}).then(res => {
							uni.hideLoading();
							uni.showToast({
								title: '已提交，待审核',
								duration: 3000 
							});
							uni.setStorageSync('applyId', this.id);
							uni.navigateBack()
						})
					}
				} else {
					uni.showToast({
						title: '请输入申请理由',
						icon: 'none',
						duration: 3000
					});
				}
			}
		}
	}
</script>

<style lang="scss">
	uni-view.u-popup {
		flex: none;
	}

	.u-textarea--radius.data-v-81cd9d32 {
		min-height: 200rpx;
	}


	.informationCss {
		display: flex;
		justify-content: space-between;
		padding: 10rpx 30rpx;
		border-bottom: 1px solid #eee;

		.imgUrl {
			max-width: 100%;
			height: 250rpx;
			margin-top: 20rpx;
		}

		.u-textarea {
			margin: 0 0 20rpx 0 !important;
		}
	}

	.informationCss1 {
		display: flex;
		padding: 20rpx 30rpx;
		border-bottom: 1px solid #eee;
	}

	.infoTextarea {
		display: flex;
		padding: 30rpx 0 30rpx 30rpx;
		margin-right: 20rpx;
	}

	.infoButton {
		display: flex;
		margin: 0 auto;
		padding: 30rpx;
	}
</style>
